package com.zggk.lzz.lzmlbj2;

import android.app.Activity;
import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.callback.StringDialogCallback;
import com.zggk.lzz.lzmladd.LzmlAddBean;
import com.zggk.lzz.lzmladd.LzmlRoadBean;
import com.zggk.lzz.lzmlbj.LzmlJsBean;
import com.zggk.lzz.mvp.BasePresenterImpl;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class LzmlBj2Presenter extends BasePresenterImpl<LzmlBj2Contract.View> implements LzmlBj2Contract.Presenter{

    @Override
    public void getData(String id , Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/lzz/roadModelMessage/roadModelAdministrator/getRoadModelAdministrator")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("id", id)
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LzmlJs2Bean lzmlJs2Bean = JSON.parseObject(response.body(),LzmlJs2Bean.class);
                        if (mView == null)
                            return;
                        if (lzmlJs2Bean.getCode().equals("200")){
                            mView.getDatas(lzmlJs2Bean.getData());
                        }else {
                            mView.onRequestError(lzmlJs2Bean.getMessage());
                        }
                    }
                });
    }
    @Override
    public void getData2( Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/lzz/roadModelMessage/roadModelAdministrator/getUserTypeList")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("userId", MyApplication.spUtils.getString("UserID"))
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LzmlJsBean lzmlJsBean = JSON.parseObject(response.body(),LzmlJsBean.class);
                        if (mView == null)
                            return;
                        if (lzmlJsBean.getCode().equals("200")){
                            mView.getData2s(lzmlJsBean.getData());
                        }else {
                            mView.onRequestError(lzmlJsBean.getMessage());
                        }
                    }
                });
    }

    @Override
    public void getData3( Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/lzz/roadModelMessage/roadModelAdministrator/getRoadList")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("pageIndex", "1")
                .params("pageSize", "100")
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LzmlRoadBean lzmlRoadBean = JSON.parseObject(response.body(),LzmlRoadBean.class);
                        if (mView == null)
                            return;
                        if (lzmlRoadBean.getCode().equals("200")){
                            mView.getData3s(lzmlRoadBean.getData());
                        }else {
                            mView.onRequestError(lzmlRoadBean.getMessage());
                        }
                    }
                });
    }
    @Override
    public void addData4(String json, Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/lzz/roadModelMessage/roadModelAdministrator/add")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("data", json)
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LzmlAddBean lzmlAddBean = JSON.parseObject(response.body(),LzmlAddBean.class);
                        if (mView == null)
                            return;
                        if (lzmlAddBean.getCode().equals("200")){
                            mView.addData4s();
                        }else {
                            mView.onRequestError(lzmlAddBean.getMessage());
                        }
                    }
                });
    }
}
